<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <jsp:include page="/resources/inc/pageHead.jsp"/>
</head>
<body>
<form class="layui-form layui-form-pane" id="_form">
    <input type="hidden" name="pid" id="pid" value="${folderId}">
    <div class="layui-form-item">
        <label class="layui-form-label">目录层级</label>
        <div class="layui-input-block">
            <input type="text" value="${folderPath}" readonly="readonly"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" for="banner">上传文件</label>
        <div class="layui-input-inline">
            <input id="banner" type="text" class="layui-input" name="banner" readonly>
        </div>
        <div class="layui-input-inline">
            <div id="picker">选择文件</div>
        </div>
        <div class="layui-form-item layui-hide " id="uploadProgress">
            <div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="uploadProgress">
                <div class="layui-progress-bar layui-bg-green" lay-percent="0%"></div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文件名称</label>
        <div class="layui-input-block">
            <input type="text" id="filename" name="filename" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文件大小</label>
        <div class="layui-input-block">
            <input type="text" value="0KB" readonly="readonly" id="size" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" type="button" id="uploadButton">开始上传</button>
        </div>
    </div>
</form>

</body>
<jsp:include page="/resources/inc/pageFooter.jsp"/>
<script src="${basePath}/resources/zheng-admin/js/upload-common.js"></script>
<script>
    $(function () {
        //上传load框
        var load;
        var commonUpload = new CommonUpload("${basePath}/manage/oss/file/system/fileUpload");
        commonUpload.setAuto(false);
        commonUpload.setUploadStart(function () {
            load = layer.load(1);
            $("#" + commonUpload.progressContainer).removeClass("layui-hide");
        });
        commonUpload.setFileQueued(function (file) {
            var size = file.size;
            if (size >= commonUpload.maxSize) {
                commonUpload.webUploader.removeFile(file);
                layer.msg("文件大小不可超过" + sizeFormat(commonUpload.maxSize), {icon: 5});
                return;
            }
            var name = file.name;
            $("#banner").val(name);
            $("#filename").val(name);
            $("#size").val(sizeFormat(size));
        });
        //文件上传结束（无论是否成功）
        commonUpload.setUploadSuccess(function (file, response) {
            layer.close(load);
            if (response.code == 1) {
                layer.msg('上传成功！！', {
                    icon: 1,
                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    FormCommon.closeDialog();
                });
            } else {
                layer.msg("上传失败！" + response.data, {icon: 5});
            }
        });
        //上传插件初始化
        commonUpload.init();

        //点击上传
        $("#uploadButton").click(function () {
            var filename = $("#filename").val();
            var pid = $("#pid").val();
            commonUpload.setFileInfo({pid: pid, filename: filename});
            commonUpload.startUpload();
        });
    });

</script>
</html>
